import { h } from 'vue';

import commonsetting from './modules/commonsetting';
import BasicLayout from '@/layouts/basic-layout';
import settings from './modules/settings';
import dataentry from './modules/dataentry'

/**
 * 在主框架内显示
 */

const frameIn = [
    {
        path: '/',
        redirect: {
            name: 'phonecard'
        },
        component: BasicLayout,
        children: [            
            // 刷新页面 必须保留
            {
                path: 'refresh',
                name: 'refresh',
                hidden: true,
                component: {
                    beforeRouteEnter (to, from, next) {
                        next(instance => instance.$router.replace(from.fullPath));
                    },
                    render: () => h()
                }
            },
            // 页面重定向 必须保留
            {
                path: 'redirect/:route*',
                name: 'redirect',
                hidden: true,
                component: {
                    beforeRouteEnter (to, from, next) {
                        next(instance => instance.$router.replace(JSON.parse(from.params.route)));
                    },
                    render: () => h()
                }
            },
            {
                path:'phonecard',
                name:'phonecard',
                meta:{
                    title:'手机卡',
                    auth:true
                },
                component: ()=> import('@/pages/phonecard')
            },            
            {
                path:'equipment',
                name:'equipment',
                meta:{
                    title:'设备',
                    auth:true
                },
                component: ()=> import('@/pages/equipment')
            },
            {
                path:'accountnumber',
                name:'accountnumber',
                meta:{
                    title:'账号',
                    auth:true
                },
                component: ()=> import('@/pages/accountnumber')
            },
            {
                path:'content',
                name:'content',
                meta:{
                    title:'内容',
                    auth:true
                },
                component: ()=> import('@/pages/content')
            },
            {
                path:'platform',
                name:'platform',
                meta:{
                    title:'平台',
                    auth:true
                },
                component: ()=> import('@/pages/platform')
            },
            {
                path:'doctor',
                name:'doctor',
                meta:{
                    title:'医生',
                    auth:true
                },
                component: ()=> import('@/pages/doctor')
            },
            {
                path:'consume',
                name:'consume',
                meta:{
                    title:'投流',
                    auth:true
                },
                component: ()=> import('@/pages/consume')
            },
            {
                path:'benchmarkingaccount',
                name:'benchmarkingaccount',
                meta:{
                    title:'对标账号',
                    auth:true
                },
                component: ()=> import('@/pages/benchmarkingaccount')
            },
            {
                path:'selecttopic',
                name:'selecttopic',
                meta:{
                    title:'选题',
                    auth:true
                },
                component: ()=> import('@/pages/selecttopic')
            },
            {
                path:'toolnavigation',
                name:'toolnavigation',
                meta:{
                    title:'素材库',
                    auth:true
                },
                component: ()=> import('@/pages/sucai')
            },
            {
                path:'ai',
                name:'ai',
                meta:{
                    title:'AI',
                    auth:true
                },
                component: ()=> import('@/pages/ai')
            }
        ]
    },
    dataentry,
    commonsetting,
    settings
    
];

/**
 * 在主框架之外显示
 */

const frameOut = [
    // 登录
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '$t:page.login.title'
        },
        component: () => import('@/pages/account/login')
    },
    // 注册
    {
        path: '/register',
        name: 'register',
        meta: {
            title: '$t:page.register.title'
        },
        component: () => import('@/pages/account/register')
    },
    // 注册结果
    {
        path: '/register/result',
        name: 'register-result',
        meta: {
            auth: true,
            title: '注册结果'
        },
        component: () => import('@/pages/account/register/result')
    }
];

/**
 * 错误页面
 */

const errorPage = [
    {
        path: '/403',
        name: '403',
        meta: {
            title: '403'
        },
        component: () => import('@/pages/system/error/403')
    },
    {
        path: '/500',
        name: '500',
        meta: {
            title: '500'
        },
        component: () => import('@/pages/system/error/500')
    },
    {
        path: '/:pathMatch(.*)',
        name: '404',
        meta: {
            title: '404'
        },
        component: () => import('@/pages/system/error/404')
    }
];

// 导出需要显示菜单的
export const frameInRoutes = frameIn;

// 重新组织后导出
export default [
    ...frameIn,
    ...frameOut,
    ...errorPage
];
